#include "plane.h"
#include"config.h"
plane::plane()
{
    //加载
    m_plane.load(":/picture/plane4.png");
    m_plane2.load(":/picture/plane1.png");
    //初始化坐标
    m_x=(Game_WIDTH-m_plane.width())/2;
    m_y=Game_HEIGHT-m_plane.height();

    //初始化边框
    m_Rect.setWidth(m_plane.width());
    m_Rect.setHeight(m_plane.height());
    m_Rect.moveTo(m_x,m_y);


    level=1;
    m_recorder1=0;
    m_recorder2=0;

   whichplane=false;
}

void plane::shoot1()
{
//时间间隔
    m_recorder1++;
//是否发射
    if(m_recorder1<m_bullet[29].Bullet_interval)
    {
        return;
    }
    else
    {
        m_recorder1=0;
        //子弹是否空闲
        for(int i=0;i<bullet_num;i++)
        {
            if(m_bullet[i].m_free)
            {
                m_bullet[i].m_free=false;
                //设置坐标
                m_bullet[i].m_x=m_x+m_Rect.width()*0.5-m_bullet[i].m_rect.width()*0.5;
                m_bullet[i].m_y=m_y-20;
                break;
            }
        }

    }

}

void plane::shoot2()
{
    //时间间隔
    m_recorder1++;
    //是否发射
    if(m_recorder1<m_bullet[29].Bullet_interval)
    {
        return;
    }
    else
    {
        m_recorder1=0;
        //子弹是否空闲
        for(int i=0;i<bullet_num/2;i++)
        {
            if(m_bullet[i].m_free)
            {
                m_bullet[i].m_free=false;
                //设置坐标
                m_bullet[i].m_x=m_x-m_bullet[i].m_rect.width()*0.5;
                m_bullet[i].m_y=m_y-20;
                break;
            }
        }
        for(int i=bullet_num/2;i<bullet_num;i++)
        {
            if(m_bullet[i].m_free)
            {
                m_bullet[i].m_free=false;
                //设置坐标
                m_bullet[i].m_x=m_x-m_bullet[i].m_rect.width()*0.5+m_Rect.width();
                m_bullet[i].m_y=m_y-20;
                break;
            }
        }
    }
}

void plane::shoot3()
{
    //时间间隔
    m_recorder1++;

    //是否发射
    if(m_recorder1<m_bullet[29].Bullet_interval)
    {
        return;
    }

    else
    {
            m_recorder1=0;
            //子弹是否空闲
            for(int i=bullet_num/3;i<(bullet_num/3)*2;i++)
            {
                if(m_bullet[i].m_free)
                {
                    m_bullet[i].m_free=false;
                    //设置坐标
                    m_bullet[i].m_x=m_x+m_Rect.width()*0.5-m_bullet[i].m_rect.width()*0.5;
                    m_bullet[i].m_y=m_y-20;
                    break;
                }
            }
    }
}


void plane::shoot4()
{
    m_recorder2++;
    if(m_recorder2<m_bullet[29].Bullet_interval+25)
    {
        return;
    }
    else
    {
        m_recorder2=0;

        for(int i=0;i<bullet_num/3;i++)
    {
        if(m_bullet[i].m_free)
        {
            m_bullet[i].m_free=false;
            //设置坐标
            m_bullet[i].m_x=m_x-m_bullet[i].m_rect.width()*0.5;
            m_bullet[i].m_y=m_y-20;
            break;
        }
    }
    for(int i=(bullet_num/3)*2;i<bullet_num;i++)
    {
        if(m_bullet[i].m_free)
        {
            m_bullet[i].m_free=false;
            //设置坐标
            m_bullet[i].m_x=m_x-m_bullet[i].m_rect.width()*0.5+m_Rect.width();
            m_bullet[i].m_y=m_y-20;
            break;
        }
    }
   }
}



void plane::setposition(int x, int y)
{
    m_x=x;
    m_y=y;

    m_Rect.moveTo(m_x,m_y);
}
